/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Schnittstellen;

import Schnittstellen.ObjectManager.Banktyp;
import java.util.Vector;

/**
 *
 * @author Geez
 */
public class Bank<E extends RTSObject> extends Vector<E> {

    private Banktyp banktyp;

    @Override
    public synchronized boolean add(E e) {
        if (e == null) {
            throw new IllegalArgumentException();
        }
        E ex = get(e.getEditorName());
        if (ex != null) {
            if (!remove(ex)) {
                return false;
            }
        }
        return super.add(e);
    }

    public synchronized E get(String name) {
        if (name == null) {
            throw new IllegalArgumentException();
        }
        for (int i = 0; i < size(); i++) {
            if (get(i) != null) {
                if (get(i).getEditorName().matches(name)) {
                    return get(i);
                }
            }
        }
        return null;
    }

    public boolean contains(String EditorName) {
        if (EditorName == null) {
            throw new IllegalArgumentException();
        }
        for (int i = 0; i < size(); i++) {
            if (get(i).getEditorName().matches(EditorName)) {
                return true;
            }
        }
        return false;
    }

    public synchronized E[] getAll() {
        RTSObject[] ret = new RTSObject[elementCount];
        for (int i = 0; i < ret.length; i++) {
            ret[i] = get(i);
        }
        return (E[]) ret;
    }

    public void setBankTyp(Banktyp b) {
        banktyp = b;
    }

    public Banktyp getBankTyp() {
        return banktyp;
    }
}
